import medicalRecordService from '../services/medicalRecord.js';
import Result from '../utils/result.js';


const medicalRecordController = { 
    async getMedicalRecord(req, res) {
        const {userId} = req.params;
        try{
            const result = await medicalRecordService.getMedicalRecord(userId);
            return res.status(200).json(result);
        }catch(err){
            return res.status(500).json(Result.error(err));
        }

    },
    async addMedicalRecord(req, res) {
        console.log('con:',req.body);

        try{   
            if(!req.body.userId){
                return res.status(400).json(Result.badRequest('userId不能为空'));
            }
            const result = await medicalRecordService.addMedicalRecord(req.body);
            return res.status(200).json(result);
        }catch(err){
            return res.status(500).json(Result.error('添加病历失败'));
        }
    },
    async delMedicalRecord(req, res) {
        const {userId,recordId}= req.body; 
        try{
            if(!userId || !recordId){
                return res.status(400).json(Result.badRequest('参数错误,缺少必要参数！'));
            }
            const result = await medicalRecordService.delMedicalRecord(recordId,userId);
            return res.status(200).json(result);
        }catch(err){
            return res.status(500).json(Result.error(err));
        }
    },
};


export default medicalRecordController;